<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增消息管理')" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-message-add">
   <!--         <div class="form-group">
                <label class="col-sm-3 control-label">管理用户ID：</label>
                <div class="col-sm-8">
                    <input name="adminUserId" class="form-control" type="text">
                </div>
            </div>-->

      <!--      <div class="form-group">
                <label class="col-sm-3 control-label">家长ID：</label>
                <div class="col-sm-8">
                    <input name="jzUserId" class="form-control" type="text">
                </div>
            </div>-->

            <div class="form-group" id="selectUser" style="display: none">
                <label class="col-sm-3 control-label is-required">选择家长：</label>
                <div class="col-sm-8">
                    <input name="jzUserId" class="form-control" type="hidden">
                    <input name="jzUserId11" class="form-control" th:value="${roleId}" type="hidden">
                </div>
                <div class="col-xs-4">
                    <select id="jzUserId" class="form-control select2-multiple">
                        <option th:each="jzUser:${jzUser}" th:value="${jzUser.userId}" th:text="${jzUser.userName}"></option>
                    </select>
                </div>
            </div>
            <input name="jzUserId11" class="form-control" th:value="${roleId}" type="hidden" id="roleId">

            <div class="form-group" id="managerMessage" style="display: none">
                <label class="col-sm-3 control-label">老师发送的消息：</label>
                <div class="col-sm-8">
                    <textarea name="messageX" class="form-control"></textarea>
                </div>
            </div>
            <div class="form-group" id="userMessage" style="display: none">
                <label class="col-sm-3 control-label">家长回复的消息：</label>
                <div class="col-sm-8">
                    <textarea name="messageJ" class="form-control"></textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: select2-js" />

    <script th:inline="javascript">
        let managerMessage = document.getElementById('managerMessage')
        let userMessage = document.getElementById('userMessage')
        let selectUser = document.getElementById('selectUser')
        let roleId = document.getElementById('roleId').value
        if (roleId==='2'){
            managerMessage.style.display='block'
            selectUser.style.display='block'
        }else if (roleId ==='4'){
            userMessage.style.display='block'
            selectUser.style.display='none'
        }
        var prefix = ctx + "system/message"
        $("#form-message-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            // 获取所选下拉框的值
            var selectedjzUserId = $('#jzUserId').val();
            // 将所选值赋给隐藏的输入文本框
            $('input[name="jzUserId"]').val(selectedjzUserId);
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-message-add').serialize());
            }
        }
    </script>
</body>
</html>